package com.music.music.web;

import com.music.common.core.utils.poi.ExcelUtil;
import com.music.common.core.web.controller.BaseController;
import com.music.common.core.web.domain.AjaxResult;
import com.music.common.core.web.page.TableDataInfo;
import com.music.common.log.annotation.Log;
import com.music.common.log.enums.BusinessType;
import com.music.common.security.annotation.RequiresPermissions;
import com.music.music.domain.Comment;
import com.music.music.service.CommentService;
import com.music.music.vo.CommentVo;
import lombok.Data;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 用户评论Controller
 *
 * @author ruoyi
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/comment/web")
public class CommentControllerWeb extends BaseController {
    @Resource
    private CommentService commentService;

    /**
     * 查询用户评论列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CommentVo commentVo) {
        startPage();
        List<CommentVo> list = commentService.selectCommentList2(commentVo);
        return getDataTable(list);
    }


    /**
     * 新增用户评论
     */
    @Log(title = "用户评论", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public AjaxResult add(@RequestBody Comment comment) {
        return toAjax(commentService.insertComment(comment));
    }

    /**
     * 删除用户评论
     */
//    @Log(title = "用户评论", businessType = BusinessType.DELETE)
//    @DeleteMapping("/delete")
//    public AjaxResult remove(Comment comment) {
//        System.out.println(comment+"------------");
//        return toAjax(commentService.deleteCommentByCommentMusicId2(comment));
//    }
    @Log(title = "用户评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult remove(Comment comment) {
        System.out.println("Received comment: " + comment); // 打印完整的 Comment 对象
        System.out.println("Comment create time: " + comment.getCommentCreateTime()); // 打印创建时间
        return toAjax(commentService.deleteCommentByCommentMusicId2(comment));
    }
}
